using System.Collections.Generic;

namespace FormicArch.AssetBundleEditor
{
    public class AssetDependency : IAssetDependency
    {
        public AssetDependency(string path, IAssetBuildManager manager, bool isMainAsset = false)
        {
            AssetPath = path;
            Manager = manager;
            IsMainAsset = isMainAsset;
        }

        public string AssetPath { get; set; }
        public IAssetBuildManager Manager { get; set; }
        public bool IsMainAsset { get; set; }
        public AssetbundleLoadType LoadType { get; set; } = AssetbundleLoadType.None;
        public List<IAssetDependency> Dependencies { get; set; } = new();
        public List<IAssetDependency> DependedOn { get; set; } = new();
        public int DependedOnCount => DependedOn.Count;


        public void AddDependency(IAssetDependency dependency)
        {
            Dependencies.Add(dependency);
        }

        public virtual void SetLoadType(AssetbundleLoadType loadType)
        {
            LoadType = loadType;
            foreach (var  dependency in Dependencies)
            {
                dependency.SetLoadType(loadType);
            }
        }

        public virtual string GetGroupName()
        {
            return Manager.GetGroupName(AssetPath);
        }

        public virtual string GetAddressPath()
        {
            return Manager.GetAddressPath(AssetPath);
        }

        public virtual void SetDependency()
        {
           
        }

        /// <summary>
        /// </summary>
        /// <param name="dependency"></param>
        public void AddDependencyOn(IAssetDependency dependency)
        {
            DependedOn.Add(dependency);
        }
    }
}